
package com.SinhalaSpellChecker;

import com.sun.star.linguistic2.LinguServiceEvent;
import com.sun.star.linguistic2.LinguServiceEventFlags;
import com.sun.star.beans.PropertyChangeEvent;
import com.sun.star.uno.XInterface;


/**
 *This class is taken from the sample spell checker code available in the examples of the
 * OpenOffice SDK and the OpenOffice wiki
 * http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Implementing_a_Spell_Checker
 * 
 */
public class PropChgHelper_Spell extends PropChgHelper
{
    /**
     * Class constructor which will pass the XInterface and string array which contains the
     * property names to the super class.
     * @param xEvtSource XInterface object
     * @param aPropNames string array
     */
    public PropChgHelper_Spell(XInterface xEvtSource, String[] aPropNames )
    {
        super( xEvtSource, aPropNames );
    }

    /**
     * Change the properties according the events occured.
     * @param aEvt PropertyChangeEvent object
     * @throws com.sun.star.uno.RuntimeException
     */
    public void propertyChange( PropertyChangeEvent aEvt )
            throws com.sun.star.uno.RuntimeException
    {
        {
            short nLngSvcFlags = 0;
            boolean bSCWA = false;  // SPELL_CORRECT_WORDS_AGAIN ?
            boolean bSWWA = false;  // SPELL_WRONG_WORDS_AGAIN ?

            boolean bVal = ((Boolean) aEvt.NewValue).booleanValue();
            if (aEvt.PropertyName.equals( "IsSinhala" ))        //Identify the property for the sinhala spell checker
            {
                bSCWA = bSWWA = true;
            }

            if (bSCWA)
                nLngSvcFlags |= LinguServiceEventFlags.SPELL_CORRECT_WORDS_AGAIN;
            if (bSWWA)
                nLngSvcFlags |= LinguServiceEventFlags.SPELL_WRONG_WORDS_AGAIN;
            if (nLngSvcFlags != 0)
            {
                LinguServiceEvent aEvent = new LinguServiceEvent( GetEvtSource(), nLngSvcFlags );
                LaunchEvent( aEvent );
            }
        }
    }

}
